//
//  DailyKLineViewController.m
//  YJCharts
//
//  Created by symbio on 2023/2/6.
//

#import "DailyKLineViewController.h"
#import <Masonry/Masonry.h>
#import <Charts/Charts-Swift.h>
#import "YJCharts-Swift.h"
#import <YYKit/YYKit.h>

@interface DailyKLineViewController ()<ChartViewDelegate>

@property (nonatomic, strong) UIView *textBackgroundView;
@property (nonatomic, strong) UILabel *openLabel;
@property (nonatomic, strong) UILabel *closeLabel;
@property (nonatomic, strong) UILabel *lowLabel;
@property (nonatomic, strong) UILabel *highLabel;

/// 混合主股票蜡烛图
@property (nonatomic, strong) CombinedChartView *combineLineStickChart;
/// 混合副图指标
@property (nonatomic, strong) CombinedChartView *combineLineChare;

/// 行情数据
@property (nonatomic, strong) NSArray<NSDictionary *> *arrChartData;

/// 垂直线
@property (nonatomic, strong) YYLabel *labVerticalLine;
/// 水平线
@property (nonatomic, strong) YYLabel *labHorizontalLine;
/// 水平线右边值
@property (nonatomic, strong) YYLabel *labHorizontalRight;

@end

@implementation DailyKLineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
    
    [self refreshData];
}
#pragma mark - refreshData
- (void)refreshData {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"USD_min5" ofType:@"json"];
    NSData *data = [[NSData alloc] initWithContentsOfFile:path];
    self.arrChartData = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:NULL];
    [self setMainCombineLineDataWithIsChange:YES];
    [self setCombineLineDataWithIsChange:YES index:0];
}

#pragma mark - 主图数据绑定

- (void)setMainCombineLineDataWithIsChange:(BOOL)isChange {
    if (self.arrChartData.count <= 0) { return; }
    
    int i = 0;
    NSMutableArray *xValues = [NSMutableArray array];
    NSMutableArray *yStockValue = [NSMutableArray array];
    
    for (NSDictionary *item in self.arrChartData) {
        [xValues addObject:[self getDateTimeWithItem:item]];
        [yStockValue addObject:[self getCandleChartDataWithItem:item index:i]];
        i += 1;
    }
    
    if (xValues.count > 0) {
        self.combineLineStickChart.xAxis.valueFormatter = [[ChartIndexAxisValueFormatter alloc] initWithValues:xValues];
        self.combineLineChare.xAxis.valueFormatter = [[ChartIndexAxisValueFormatter alloc] initWithValues:xValues];
    }
    
    /// MA
    if ([MarketSetting mainCurrentIndex] == 0) {
        NSDictionary *kpiMainData = [self getDicKpiMainData:self.arrChartData];
        [MarketSetting setDicKpiMainData:kpiMainData];
        
        [self setMainKpiDataForValues1:kpiMainData[@"MA5"]
                               values2:kpiMainData[@"MA10"]
                               values3:kpiMainData[@"MA15"]
                               values4:kpiMainData[@"MA20"]
                           yStockValue:yStockValue
                              isChange:isChange];
    } else if ([MarketSetting mainCurrentIndex] == 1) {
        NSDictionary *kpiMainData = [BOLL calcBOLLForData:self.arrChartData andNumber:26 withP:2];
        [MarketSetting setDicKpiMainData:kpiMainData];
        [self setMainKpiDataForValues1:kpiMainData[@"up"]
                               values2:kpiMainData[@"mid"]
                               values3:kpiMainData[@"low"]
                               values4:nil
                           yStockValue:yStockValue
                              isChange:isChange];
    }
}

- (void)setMainKpiDataForValues1:(NSArray<NSNumber *> *)values1
                         values2:(NSArray<NSNumber *> *)values2
                         values3:(NSArray<NSNumber *> *)values3
                         values4:(NSArray<NSNumber *> *)values4
                     yStockValue:(NSArray<ChartDataEntry *> *)yStockValue
                        isChange:(BOOL)isChange {
    
    NSMutableArray *yV1 = [NSMutableArray array];
    NSMutableArray *yV2 = [NSMutableArray array];
    NSMutableArray *yV3 = [NSMutableArray array];
    NSMutableArray *yV4 = [NSMutableArray array];
    
    for (NSInteger i = self.arrChartData.count - values1.count; i < self.arrChartData.count; i++) {
        [yV1 addObject:[[ChartDataEntry alloc] initWithX:i y:[values1[i - (self.arrChartData.count - values1.count)] doubleValue]]];
    }
    
    for (NSInteger i = self.arrChartData.count - values2.count; i < self.arrChartData.count; i++) {
        [yV2 addObject:[[ChartDataEntry alloc] initWithX:i y:[values2[i - (self.arrChartData.count - values2.count)] doubleValue]]];
    }
    
    for (NSInteger i = self.arrChartData.count - values3.count; i < self.arrChartData.count; i++) {
        [yV3 addObject:[[ChartDataEntry alloc] initWithX:i y:[values3[i - (self.arrChartData.count - values3.count)] doubleValue]]];
    }
    if (values4 != nil) {
        for (NSInteger i = self.arrChartData.count - values4.count; i < self.arrChartData.count; i++) {
            [yV4 addObject:[[ChartDataEntry alloc] initWithX:i y:[values4[i - (self.arrChartData.count - values4.count)] doubleValue]]];
        }
    }
    
    CombinedChartData *data = [[CombinedChartData alloc] init];
    NSMutableArray *ds = [NSMutableArray array];
    [ds addObject:[MarketSetting setLineDataForValues:yV1 andColor:MarketSetting.dif_color withName:@""]];
    [ds addObject:[MarketSetting setLineDataForValues:yV2 andColor:MarketSetting.dea_color withName:@""]];
    [ds addObject:[MarketSetting setLineDataForValues:yV3 andColor:MarketSetting.kmacd_color withName:@""]];
    if (values4 != nil) {
        [ds addObject:[MarketSetting setLineDataForValues:yV4 andColor:MarketSetting.kother_color withName:@""]];
    }
    
    data.lineData = [[LineChartData alloc] initWithDataSets:ds];
    
    data.candleData = [[CandleChartData alloc] initWithDataSets:@[[MarketSetting setStockDataSetForValues:yStockValue]]];
    
    self.combineLineStickChart.data = data;
    if (isChange) {
        [self.combineLineStickChart animateWithXAxisDuration:[MarketSetting timeInterval]];
    }
    /// 开局移动到最右边xMax为最大x轴值
    [self.combineLineStickChart moveViewToX:self.combineLineStickChart.data.xMax];
}

- (NSDictionary *)getDicKpiMainData:(NSArray *)data {
    return @{
            @"MA5": [self calcMAData:data andNumbner:5 withFiled:@"Close"],
            @"MA10": [self calcMAData:data andNumbner:10 withFiled:@"Close"],
            @"MA15": [self calcMAData:data andNumbner:15 withFiled:@"Close"],
            @"MA20": [self calcMAData:data andNumbner:30 withFiled:@"Close"]
    };
}

/// 计算MA均线
/// - Parameters:
///   - d: 数据源
///   - n: MA时间窗口 5,10,20,60
///   - f: 计算字段
/// - Returns: [Double]
- (NSArray<NSNumber *> *)calcMAData:(NSArray *)data andNumbner:(NSInteger)numbner withFiled:(NSString *)filed {
    
    if (filed.length <= 0) {
        return @[];
    }
    
    double sum = 0;
    NSMutableArray *muarr = [NSMutableArray array];
    
    for (int i = 0; i < data.count; i++) {
        if (i < numbner-1) {
            continue;
        }
        
        sum = 0;
        for (int j = 0; j < numbner; j++) {
            NSDictionary *item = data[i-j];
            double value = [item[filed] doubleValue];
            sum += value;
        }
        [muarr addObject:[NSNumber numberWithDouble:sum/numbner]];
    }
    
    return muarr;
}

- (CandleChartDataEntry *)getCandleChartDataWithItem:(NSDictionary *)item index:(int)index {
    return [[CandleChartDataEntry alloc] initWithX:index
                                           shadowH:[item[@"High"] doubleValue]
                                           shadowL:[item[@"Low"] doubleValue]
                                              open:[item[@"Open"] doubleValue]
                                             close:[item[@"Close"] doubleValue]];
}

- (NSString *)getDateTimeWithItem:(NSDictionary *)item {
    NSInteger dateTime = [item[@"UpdateTime"] integerValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateTime];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"MM/dd HH:mm";
    return [dateFormatter stringFromDate:date];
}

#pragma mark - 副图指标数据绑定

/// 指标图数据绑定
- (void)setCombineLineDataWithIsChange:(BOOL)isChange index:(NSInteger)index {
    if (self.arrChartData.count <= 0) {
        return;
    }
    
    if (index == 0) {
        NSDictionary *dicKpiData = [MACD calcMACDForData:self.arrChartData andShort:12 andLong:26 andMid:9 withFiled:@"Close"];
        MarketSetting.dicKpiData = dicKpiData;
        
        [self setMACDForDIF:dicKpiData[@"DIF"] DEA:dicKpiData[@"DEA"] MACD:dicKpiData[@"MACD"] isChange:isChange];
    } else if (index == 1) {
        NSDictionary *dicKpiData = [KDJ calcKDJForData:self.arrChartData andNumber:9 andK:3 withD:3];
        [self setKDJForK:dicKpiData[@"K"] D:dicKpiData[@"D"] J:dicKpiData[@"J"] isChange:isChange];
    }
}

- (void)setMACDForDIF:(NSArray<NSNumber *> *)DIF
                  DEA:(NSArray<NSNumber *> *)DEA
                 MACD:(NSArray<NSNumber *> *)MACD
             isChange:(BOOL)isChange {
    NSMutableArray *yDIFValues = [NSMutableArray array];
    NSMutableArray *yDEAValues = [NSMutableArray array];
    NSMutableArray *yMACDValues = [NSMutableArray array];
    
    for (int i = 0; i < DIF.count; i++) {
        [yDIFValues addObject:[[ChartDataEntry alloc] initWithX:i y:[DIF[i] doubleValue]]];
    }
    
    for (int i = 0; i < DEA.count; i++) {
        [yDEAValues addObject:[[ChartDataEntry alloc] initWithX:i y:[DEA[i] doubleValue]]];
    }
    
    for (int i = 0; i < MACD.count; i++) {
        [yMACDValues addObject:[[BarChartDataEntry alloc] initWithX:i y:[MACD[i] doubleValue]]];
    }
    
    CombinedChartData *data = [[CombinedChartData alloc] init];
    
    data.lineData = [[LineChartData alloc] initWithDataSets:@[
        [MarketSetting setLineDataForValues:yDIFValues andColor:MarketSetting.dif_color withName:@"DIF"],
        [MarketSetting setLineDataForValues:yDEAValues andColor:MarketSetting.dea_color withName:@"DEA"]
    ]];
    
    data.barData = [[BarChartData alloc] initWithDataSets:@[
        [MarketSetting setBarCharSetForValues:yMACDValues withName:@"MACD"]
    ]];
    
    self.combineLineChare.data = data;
    
    if (isChange) {
        [self.combineLineChare animateWithXAxisDuration:MarketSetting.timeInterval];
    }
    
    /// 开局移动到最右边xMax为最大x轴值
    [self.combineLineChare moveViewToX:self.combineLineChare.data.xMax];
}
- (void)setKDJForK:(NSArray<NSNumber *> *)K
                 D:(NSArray<NSNumber *> *)D
                 J:(NSArray<NSNumber *> *)J
          isChange:(BOOL)isChange {
    NSMutableArray *yKValues = [NSMutableArray array];
    NSMutableArray *yDValues = [NSMutableArray array];
    NSMutableArray *yJValues = [NSMutableArray array];
    
    for (int i = 0; i < K.count; i++) {
        [yKValues addObject:[[ChartDataEntry alloc] initWithX:i y:[K[i] doubleValue]]];
    }
    
    for (int i = 0; i < D.count; i++) {
        [yDValues addObject:[[ChartDataEntry alloc] initWithX:i y:[D[i] doubleValue]]];
    }
    
    for (int i = 0; i < J.count; i++) {
        [yJValues addObject:[[ChartDataEntry alloc] initWithX:i y:[J[i] doubleValue]]];
    }
    
    CombinedChartData *data = [[CombinedChartData alloc] init];
    
    data.lineData = [[LineChartData alloc] initWithDataSets:@[
        [MarketSetting setLineDataForValues:yKValues andColor:MarketSetting.dif_color withName:@"K"],
        [MarketSetting setLineDataForValues:yDValues andColor:MarketSetting.dea_color withName:@"D"],
        [MarketSetting setLineDataForValues:yJValues andColor:MarketSetting.kmacd_color withName:@"J"],
    ]];
    
    self.combineLineChare.data = data;
    
    if (isChange) {
        [self.combineLineChare animateWithXAxisDuration:MarketSetting.timeInterval];
    }
    
    /// 开局移动到最右边xMax为最大x轴值
    [self.combineLineChare moveViewToX:self.combineLineChare.data.xMax];
}

#pragma mark - setupUI

- (void)setupUI {
    [self setupUITopView];
    [self setupUIMainDailyKLine];
    [self setupUICombineLineChare];
    [self setupUICrosshair];
    [self addGestureRecognizer];
}

#pragma mark - ChartViewDelegate

/// 图表被移动(主、副图同时响应)
/// https://blog.csdn.net/dianchidu6913/article/details/101228178
/// - Parameters:
///   - chartView: ChartViewBase
///   - dX: CGFloat
///   - dY: CGFloat
- (void)chartTranslated:(ChartViewBase *)chartView dX:(CGFloat)dX dY:(CGFloat)dY {
    [self updateTouchForChartView:chartView];
}

/// 图表被缩放
/// - Parameters:
///   - chartView: ChartViewBase
///   - scaleX: CGFloat
///   - scaleY: CGFloat
- (void)chartScaled:(ChartViewBase *)chartView scaleX:(CGFloat)scaleX scaleY:(CGFloat)scaleY {
    [self updateTouchForChartView:chartView];
}

/// 同步手势
/// - Parameter chartView: chartView description
- (void)updateTouchForChartView:(ChartViewBase *)chartView {
    CGAffineTransform srcMatrix = chartView.viewPortHandler.touchMatrix;
    [self.combineLineStickChart.viewPortHandler refreshWithNewMatrix:srcMatrix chart:self.combineLineStickChart invalidate:true];
    [self.combineLineChare.viewPortHandler refreshWithNewMatrix:srcMatrix chart:self.combineLineChare invalidate:true];
}



#pragma mark - 混合副图指标

- (void)setupUICombineLineChare {
    [self.view addSubview:self.combineLineChare];
    [self.combineLineChare mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.combineLineStickChart.mas_bottom);
        make.height.mas_equalTo(120);
    }];
}

- (CombinedChartView *)combineLineChare {
    if (!_combineLineChare) {
        _combineLineChare = [[CombinedChartView alloc] init];
        /// 设置动画时间
        [_combineLineChare animateWithXAxisDuration:[MarketSetting timeInterval]];
        
        /// 整体样式
        [MarketSetting setGradStyleForChart:_combineLineChare
                      andShowGridBackground:false
                                withBGColor:[UIColor clearColor]
                             andShowBorders:false
                             andBorderColor:[UIColor clearColor]
                             withEdgeInsets:(UIEdgeInsetsMake(0, 10, 0, 1.5))
                                andDelegate:self];
        
        /// 底部横轴样式
        [MarketSetting setBottomCalibrationStyleForChart:_combineLineChare
                                               andIsShow:false
                                           withShowCount:0];
        /// 缩放样式
        [MarketSetting setZoomStyleForChart:_combineLineChare];
        
        /// 空视图样式
        [MarketSetting setEmptyStyleForChart:_combineLineChare];
        
        /// 右边刻度样式
        [MarketSetting setRightCalibrationStyleForChart:_combineLineChare
                                           andShowCount:3];
    }
    return _combineLineChare;
}

#pragma mark - K线主视图

- (void)setupUIMainDailyKLine {
    [self.view addSubview:self.combineLineStickChart];
    [self.combineLineStickChart mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.textBackgroundView.mas_bottom);
        make.height.mas_equalTo(400);
    }];
}

- (CombinedChartView *)combineLineStickChart {
    if (!_combineLineStickChart) {
        _combineLineStickChart = [[CombinedChartView alloc] init];
        //缩放样式
        [MarketSetting setZoomStyleForChart:_combineLineStickChart];
        //空视图样式
        [MarketSetting setEmptyStyleForChart:_combineLineStickChart];
        //右边刻度样式
        [MarketSetting setRightCalibrationStyleForChart:_combineLineStickChart andShowCount:7];
        
        //底部横轴样式
        [MarketSetting setBottomCalibrationStyleForChart:_combineLineStickChart andIsShow:true withShowCount:3];
        
        //整体样式
        [MarketSetting setGradStyleForChart:_combineLineStickChart
                      andShowGridBackground:false
                                withBGColor:UIColor.clearColor
                             andShowBorders:false
                             andBorderColor:UIColor.clearColor
                             withEdgeInsets:(UIEdgeInsetsMake(10, 10, 0, 0)) andDelegate:self];
    }
    return _combineLineStickChart;
}

#pragma mark - TopView

- (void)setupUITopView {
    [self.view addSubview:self.textBackgroundView];
    [self.textBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(50);
    }];
    
    [self.textBackgroundView addSubview:self.openLabel];
    [self.openLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.textBackgroundView);
    }];
    
    [self.textBackgroundView addSubview:self.closeLabel];
    [self.closeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.textBackgroundView);
        make.left.equalTo(self.openLabel.mas_right);
        make.width.equalTo(self.openLabel.mas_width);
    }];
    
    [self.textBackgroundView addSubview:self.lowLabel];
    [self.lowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.textBackgroundView);
        make.left.equalTo(self.closeLabel.mas_right);
        make.width.equalTo(self.openLabel.mas_width);
    }];
    
    [self.textBackgroundView addSubview:self.highLabel];
    [self.highLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(self.textBackgroundView);
        make.left.equalTo(self.lowLabel.mas_right);
        make.width.equalTo(self.openLabel.mas_width);
    }];
}

- (UIView *)textBackgroundView {
    if (!_textBackgroundView) {
        _textBackgroundView = [[UIView alloc] init];
    }
    return _textBackgroundView;
}

- (UILabel *)openLabel {
    if (!_openLabel) {
        _openLabel = [[UILabel alloc] init];
        _openLabel.text = @"开盘";
        _openLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _openLabel;
}

- (UILabel *)closeLabel {
    if (!_closeLabel) {
        _closeLabel = [[UILabel alloc] init];
        _closeLabel.text = @"收盘";
        _closeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _closeLabel;
}

- (UILabel *)lowLabel {
    if (!_lowLabel) {
        _lowLabel = [[UILabel alloc] init];
        _lowLabel.text = @"最低";
        _lowLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _lowLabel;
}

- (UILabel *)highLabel {
    if (!_highLabel) {
        _highLabel = [[UILabel alloc] init];
        _highLabel.text = @"最高";
        _highLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _highLabel;
}

#pragma mark - 十字线

- (void)setupUICrosshair {
    [self.view addSubview:self.labVerticalLine];
    [self.view addSubview:self.labHorizontalLine];
    [self.view addSubview:self.labHorizontalRight];
    
    [self.labVerticalLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(0.5);
        make.top.mas_equalTo(10);
        make.right.mas_equalTo(0);
        make.bottom.equalTo(self.combineLineChare.mas_bottom).offset(-10);
    }];
    
    [self.labHorizontalLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-30);
        make.left.mas_equalTo(10);
    }];
    
    [self.labHorizontalRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(30);
        make.right.mas_equalTo(0);
    }];
}

- (YYLabel *)labVerticalLine {
    if (!_labVerticalLine) {
        _labVerticalLine = [[YYLabel alloc] init];
        _labVerticalLine.backgroundColor = MarketSetting.highlightColor;
        _labVerticalLine.opaque = false;
        //异步显示
        _labVerticalLine.displaysAsynchronously = true;
        _labVerticalLine.hidden = YES;
    }
    return _labVerticalLine;
}

- (YYLabel *)labHorizontalLine {
    if (!_labHorizontalLine) {
        _labHorizontalLine = [[YYLabel alloc] init];
        _labHorizontalLine.backgroundColor = MarketSetting.highlightColor;
        _labHorizontalLine.opaque = false;
        //异步显示
        _labHorizontalLine.displaysAsynchronously = true;
        _labHorizontalLine.hidden = YES;
    }
    return _labHorizontalLine;
}

- (YYLabel *)labHorizontalRight {
    if (!_labHorizontalRight) {
        _labHorizontalRight = [[YYLabel alloc] init];
        _labHorizontalRight.backgroundColor = MarketSetting.highlightColor;
        _labHorizontalRight.opaque = false;
        //异步显示
        _labHorizontalRight.displaysAsynchronously = true;
        _labHorizontalRight.text = @"0.0";
        _labHorizontalRight.font = [UIFont systemFontOfSize:10];
        _labHorizontalRight.textColor = [UIColor colorFromHexIntWithHex:0xffffff alpha:0.6];
        _labHorizontalRight.hidden = YES;
    }
    return _labHorizontalRight;
}

#pragma mark - 手势
- (void)addGestureRecognizer {
    UILongPressGestureRecognizer *longGest = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGestAction:)];
    longGest.minimumPressDuration = 1;
    [self.view addGestureRecognizer:longGest];
}

- (void)longGestAction:(UILongPressGestureRecognizer *)sender {
    CGPoint transPoint = [sender locationInView:self.combineLineStickChart];
    if (transPoint.x > [UIScreen mainScreen].bounds.size.width - 30) {
        return;
    }
}



//MARK:主图指标值
/// 更新顶部主图指标
/// - Parameter ix: Int
- (void)updateTopViewForIndex:(NSInteger)index {
    
}

//MARK:十字线数值
/// 更新右边水平十字线数值
/// - Parameter p: CGPoint
- (void)updateRightViewForPoint:(CGPoint)point {
    self.labHorizontalRight.centerY = self.labHorizontalLine.centerY;
    
    CGFloat min = 0;
    CGFloat max = 0;
    CGFloat unitValue = 0;
    CGFloat haveHight = 0;
    
    /// 匹配主图刻度值
    if (point.y >= self.combineLineStickChart.top && point.y <= self.combineLineStickChart.bottom) {
        min = self.combineLineStickChart.rightAxis.axisMinimum;
        max = self.combineLineStickChart.rightAxis.axisMaximum;
        
        //计算单位高度的值
        unitValue = (max - min) / self.combineLineStickChart.height;
        
        //拥有的单位高度
        haveHight = point.y - self.combineLineStickChart.top;
    } else if (point.y >= self.combineLineChare.top && point.y <= self.combineLineChare.bottom) {
        /// 匹配附图刻度值
        min = self.combineLineChare.rightAxis.axisMinimum;
        max = self.combineLineChare.rightAxis.axisMaximum;
        
        //计算单位高度的值
        unitValue = (max - min) / self.combineLineChare.height;
        
        //拥有的单位高度
        haveHight = point.y - self.combineLineChare.top;
    }

    //赋值
    if (max > 0) {
        self.labHorizontalRight.text = [NSString stringWithFormat:@"%.2f",max - unitValue * haveHight];
    }
}

@end
